import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class AnimatedAlignDemo extends StatelessWidget {
  const AnimatedAlignDemo({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("AnimatedAlign"),
      ),
      body: const AnimatedAlignExample(),
    );
  }
}

class AnimatedAlignExample extends StatefulWidget {
  const AnimatedAlignExample({super.key});

  @override
  State<StatefulWidget> createState() {
    return _AnimatedAlignExampleState();
  }
}

class _AnimatedAlignExampleState extends State<AnimatedAlignExample> {
  bool selected = false;

  updateSelect() {
    setState(() {
      selected = !selected;
    });
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => updateSelect(),
      child: Center(
        child: Container(
          width: 250,
          height: 250,
          color: Colors.red,
          child: AnimatedAlign(
            alignment: selected ? Alignment.topRight : Alignment.bottomLeft,
            duration: const Duration(seconds: 1),
            curve: Curves.fastOutSlowIn,
            child: const FlutterLogo(
              size: 60,
            ),
          ),
        ),
      ),
    );
  }
}
